package test.keen.app

import androidx.compose.foundation.layout.Column
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import me.fung.keen.app.view.BasePresenter
import me.fung.keen.app.view.View

class Model {
    var text: String by mutableStateOf(value = "")
}

class TestPresenter : BasePresenter() {
    val model = Model()
    fun test() {
        model.text = "Hello, World!"
    }
}

// 测试View
class TestView : View<TestPresenter>() {
    @Composable
    override fun content(modifier: Modifier) {
        Column {
            Text("Hello, World!")
            Button(
                onClick = {
                    p.test()
                }
            ) {
                Text("Click me!")
            }
            Text(p.model.text)
        }
    }

    @Composable
    override fun show(modifier: Modifier) {
        content(modifier)
    }
}

fun main() {
    application {
        Window(onCloseRequest = ::exitApplication) {
            TestView().show(Modifier)
        }
    }
}